package com.ruoyi.business.controller;


import com.ruoyi.business.service.IWsdMealRefundsService;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.WsdMealRefunds;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 *
 * 请假期间的餐费退款记录表
 * @author wwq
 * @since 2024-05-20
 */
@RestController
@RequestMapping("/wsd-meal-refunds")
public class WsdMealRefundsController extends BaseController {

    @Autowired
    private IWsdMealRefundsService wsdMealRefundsService;

    /**
     * 查询请假期间的餐费退款记录列表
     */
    @PreAuthorize("@ss.hasPermi('business:refunds:list')")
    @GetMapping("/list")
    public TableDataInfo list(WsdMealRefunds wsdMealRefunds) {
        startPage();
        List<WsdMealRefunds> list = wsdMealRefundsService.selectWsdMealRefundsList(wsdMealRefunds);
        return getDataTable(list);
    }

    /**
     * 导出请假期间的餐费退款记录列表
     */
    @PreAuthorize("@ss.hasPermi('business:refunds:export')")
    @Log(title = "请假期间的餐费退款记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WsdMealRefunds wsdMealRefunds)
    {
        List<WsdMealRefunds> list = wsdMealRefundsService.selectWsdMealRefundsList(wsdMealRefunds);
        ExcelUtil<WsdMealRefunds> util = new ExcelUtil<WsdMealRefunds>(WsdMealRefunds.class);
        util.exportExcel(response, list, "请假期间的餐费退款记录数据");
    }

    /**
     * 获取请假期间的餐费退款记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:refunds:query')")
    @GetMapping(value = "/{mealRefundsId}")
    public AjaxResult getInfo(@PathVariable("mealRefundsId") Long mealRefundsId) {
        return success(wsdMealRefundsService.selectWsdMealRefundsByMealRefundsId(mealRefundsId));
    }

    /**
     * 新增请假期间的餐费退款记录
     */
    @PreAuthorize("@ss.hasPermi('business:refunds:add')")
    @Log(title = "请假期间的餐费退款记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WsdMealRefunds wsdMealRefunds)
    {
        return toAjax(wsdMealRefundsService.insertWsdMealRefunds(wsdMealRefunds));
    }

    /**
     * 审核请假期间的餐费退款记录
     */
//    @PreAuthorize("@ss.hasPermi('business:refunds:edit')")
//    @Log(title = "请假期间的餐费退款记录", businessType = BusinessType.UPDATE)
    @PutMapping
    @Anonymous
    public AjaxResult edit(@RequestBody WsdMealRefunds wsdMealRefunds) {
        return toAjax(wsdMealRefundsService.updateWsdMealRefunds(wsdMealRefunds));
    }

    /**
     * 删除请假期间的餐费退款记录
     */
    @PreAuthorize("@ss.hasPermi('business:refunds:remove')")
    @Log(title = "请假期间的餐费退款记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{mealRefundsIds}")
    public AjaxResult remove(@PathVariable Long[] mealRefundsIds)
    {
        return toAjax(wsdMealRefundsService.deleteWsdMealRefundsByMealRefundsIds(mealRefundsIds));
    }
}
